<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>借阅信息列表</title>
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <script src="../../demo/demo.css" type="text/javascript"></script>
    <script src="../../utils/DateUtil.js" type="text/javascript"></script>

    <style type="text/css">
      html, body{
          margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
      } 
      </style>
</head>
<body>
  <body>
    <h1>借阅信息列表</h1>

    <div style=" width: 100%;">
        <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>   
                    </td>
                </tr>
            </table>           
        </div>
    </div>


    </div>
    <!--撑满页面-->
    <div class="mini-fit" >
      <div id="bookInfoDatagrid" class="mini-datagrid" style="width:100%;height:100%;"
        url="/bookmanagement/borrowinfolistaction?method=queryBorrowInfo" idField="id" multiSelect="true" 
      >
          <div property="columns">
            <div name="bookid"></div>
            <div type="indexcolumn" width="30">序号</div>       
            <!-- <div type="checkcolumn" ></div> -->
            <div field="borrowid" width="80" headerAlign="center">借阅编号</div>
            <div field="bookname" width="80" headerAlign="center">图书名称</div>  
            <div field="borrower" width="60" headerAlign="center">借阅人</div>
            <div field="phone" width="60" headerAlign="center">详细电话</div> 
            <div field="borrowtime" width="80" headerAlign="center" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss">借阅时间</div>
            <div field="returntime" width="80" headerAlign="center"  dateFormat="yyyy-MM-dd HH:mm:ss">归还时间</div>
            <!--操作-->
            <div field="optionButton" width="60" headerAlign="center" align="center" renderer="onOptionRenderer">操作</div>                     
          </div>
      </div>
    </div>
    

<script type="text/javascript">
    mini.parse();

    // 获取表格信息
    var grid = mini.get("bookInfoDatagrid");
    grid.load();
    grid.hideColumn("bookid");

    //////////////控件渲染///////////////////////////////
    // 操作按钮渲染
    function onOptionRenderer(e) {
      var id = e.row.borrowid;
      var bookid = e.row.bookid;
      var returntime = e.row.returntime;
      var str = '<a class="mini-button" onclick="deleteBorrowInfo(\''+ id +'\')">删除</a>' + '&nbsp;';
      var str1 = '<a class="mini-button" onclick="returnBookInfo(\'' + id + '\',\'' + bookid + '\')">归还</a>' + '&nbsp;';
      if (returntime == null || returntime === "" ) {
        return str1;
      } else {
        return str;
      }
    }



    //////////////控件事件///////////////////////////////
    function editBookInfo(id) {
      mini.open({
        url: bootPATH + "../pages/bookinfo/bookinfoedit.html",
        title: "图书信息编辑", 
        width: 600, height: 400,
        onload: function() {
          var iframe = this.getIFrameEl();
          var data = { action: "edit", bookId: id };
          iframe.contentWindow.SetData(data);
        },
        ondestroy: function(action) {
          grid.reload();
        }
      })
    }
    // 删除按钮方法
    function deleteBorrowInfo(id) {
        deleteByBookIdAjax(id)
    }

    // 归还按钮方法
    function returnBookInfo(borrowId, bookId) {
        mini.confirm("确定归还该书吗？", '提示', function (action) {
            if (action == "ok") {
              returnBookAjax(borrowId, bookId);
            } 
        })
    }
    

    /////////////页面跳转//////////////////////////////
    // 新增页
    function add() {
        mini.open({
            url: bootPATH + "../pages/borrowinfo/borrowinfoadd.html",
            title: "新增借阅信息", 
            width: 600, height: 450,
            onload: function () {
              var iframe = this.getIFrameEl();
              var data = { action: "borrowinfolist"};
              iframe.contentWindow.setData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }


    ///////////////ajax请求//////////////////////////
    // 根据id删除的请求
    function deleteByBookIdAjax(id) {
        mini.confirm("确定删除选中记录？", '提示', function (action) {
            if (action == "ok") {
                $.ajax({
                    url: "/bookmanagement/borrowinfoeditaction?method=deleteBorrowInfoByBorrowId&borrowId=" + id,
                    type: 'GET',
                    cache: false,
                    success: function (text) {
                        mini.alert(text, "提示", function (action) {
                            grid.reload();
                        })
                    },
                    error: function () {
                    }
                });
            }
        })
    }

    // 根据id还书
    function returnBookAjax(borrowId, bookId) {
      $.ajax({
          url: "/bookmanagement/borrowinfoeditaction?method=returnBook&borrowId=" + borrowId + "&bookId=" + bookId,
          type: 'GET',
          cache: false,
          success: function (text) {
              mini.alert(text, "提示", function (action) {
                  grid.reload();
                  // CloseEvent
              })
          },
          error: function () {
          }
      });
    }

</script>
</body>
</html>